import Phaser from '../../lib/phaser3.esm.js'

export default class GameOver extends Phaser.Scene {
  /** @type {number} */
  collected
  /** @type {number} */
  textY

  constructor () {
    super('gameover')
  }
  init (data) {
    this.collected = data.collected
    this.textY = 0.4
  }
  create () {
    this.addText('Game Over', 48)
    this.addText(`you got ${this.collected} carrots!`, 24)
    this.addText('press space to play again', 24)
    this.input.keyboard.once('keydown-SPACE', () => {
      this.scene.start('game')
    })
  }
  addText (text, fontSize) {
    const { width, height } = this.scale
    this.add.text(
      width * 0.5,
      height * this.textY,
      text,
      { fontSize }
    ).setOrigin(0.5)
    this.textY += fontSize / 480
  }
}